package com.kmu.lycan.dao.impl;

import com.kmu.lycan.dao.LoginDao;
import com.kmu.lycan.entity.LoginDetail;
import com.kmu.lycan.factory.HibernateFactory;
import com.sun.corba.se.spi.monitoring.StringMonitoredAttributeBase;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.query.Query;

import javax.xml.soap.Detail;

public class LoginDaoImp implements LoginDao {

    @Override
    public LoginDetail validateUser(String studentNo, String token) {

        Session session =HibernateFactory.getSession();
        Transaction transaction = session.beginTransaction();
        Query query = session.createQuery("from LoginDetail where studentNo = ?1 and token = ?2")
                .setParameter(1, studentNo)
                .setParameter(2, token)
                .setMaxResults(1);
        LoginDetail loginDetail = (LoginDetail) query.uniqueResult();
        transaction.commit();
        session.close();
        return loginDetail;
    }
}
